INC=-I ../framework -I ../third -I ../lua -I ../lua_3rd -I ../lsheeps -I ../lserverhook
LIB=-pthread -ldl -rdynamic -lssl -lcrypto -L../lsheeps -llsheeps -L../lua_3rd -llua3rd -L../lua -llua -L../framework -lframework -L../network -lnetwork -L../third -lthird -L../lserverhook -lserverhook
TARGET=libsheeps.so
OBJ=favicon.o logic.o echarts_min.o jquery_min.o console.o report.o book.o katex_min.o dllmain.o sheeps.o BridgeProtocol.o

CC=gcc
CXX=g++ -std=c++11
CFLAGS=-g -O2 -pipe -Wall -fno-strict-aliasing -D_GNU_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64 -fPIC

all: clearfile copyfile
	make build OUT_CONFIG=-D_DEBUG
	make clearfile

release: clearfile copyfile
	make build OUT_CONFIG=-DNDEBUG
	make clearfile

build: $(TARGET)

clearfile:
	rm -f *.html *.css *.js *.ico

copyfile:
	cp ../web/console.html ./
	cp ../web/report.html ./
	cp ../web/book.html ./
	cp ../web/katex.min.css ./katex_min.css
	cp ../web/jquery.min.js ./jquery_min.js
	cp ../web/echarts.min.js ./echarts_min.js
	cp ../web/logic.js ./logic.js
	cp ../web/favicon.ico ./

$(TARGET):$(OBJ)
	$(CXX) $(CFLAGS) $(OUT_CONFIG) -Wl,-rpath=./ -shared -o $@ $^ $(LIB)
%.o: %.cpp
	$(CXX) $(CFLAGS) $(OUT_CONFIG) $(INC) -c $<
%.o: %.c
	$(CC) $(CFLAGS) $(OUT_CONFIG) $(INC) -c $<
%.o: %.html
	ld -r -b binary -o $@ $<
%.o: %.css
	ld -r -b binary -o $@ $<
%.o: %.js
	ld -r -b binary -o $@ $<
%.o: %.ico
	ld -r -b binary -o $@ $<

clean: clearfile
	rm -f *.o *.so
	rm -f $(TARGET)
